package com.example.redisscene.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

@Service
public class HashService {

    private static String KEY = "HASH";

    @Autowired
    private RedisTemplate redisTemplate;

    public void setOrderOccupyCabinet(String readyNumber,String doorNumber,String orderNumber) {
        redisTemplate.opsForHash().put(KEY, readyNumber + "-" + doorNumber, orderNumber);
    }

    public void releaseCabinetOrder(String readyNumber,String doorNumber) {
        redisTemplate.opsForHash().delete(KEY, readyNumber + "-" + doorNumber);
    }

    public void getAllAliveOrder() {
        List<String> values = redisTemplate.opsForHash().values(KEY);
        System.out.println(values);
    }

    public void getAllHadOccupyCabinet() {
        Set keys = redisTemplate.opsForHash().keys(KEY);
        System.out.println(keys);
    }

}
